/******************************************

@Author :yinjinlin<yinjinlin_uplook@163.com>
@Time : 2020/12/1 下午1:09

*******************************************/
package main

import (
	"context"
	"encoding/json"
	"git.900sui.cn/kc/base/utils"
	"git.900sui.cn/kc/kcgin"
	"git.900sui.cn/kc/kcgin/logs"
	"git.900sui.cn/kc/rabbitmq"
	"git.900sui.cn/kc/rpcinterface/client/comtreeData"
	"git.900sui.cn/kc/rpcinterface/client/dataVisualization"
	dataVisualization2  "git.900sui.cn/kc/rpcinterface/interface/dataVisualization"
	"git.900sui.cn/kc/rpcinterface/interface/task/insurance"
	"github.com/streadway/amqp"
)

func main(){

	//  ---初始化出口consumer
	rpcdvl := new(dataVisualization.CardPackagePolicy).Init()
	defer rpcdvl.Close()

	rpcComtreeData := new(comtreeData.Consumption).Init()
	defer rpcComtreeData.Close()


	logs.Info("Environment Variable:MSF_ENV:", kcgin.KcConfig.RunMode)
	new(utils.KcLog).GetInstance(kcgin.AppConfig.String("insurance.log.cardpackpolicyTask"))
	// 连接交换机
	err := rabbitmq.Rabbitmq.Consume(kcgin.AppConfig.String("insurance.queue.cardpackpolicyTask"), func(msg amqp.Delivery) {
		//  rpcTask interface  队列任务的入口 producer
		var res insurance.ArgsCardPackPolicySuc
		if err := json.Unmarshal(msg.Body, &res); err != nil {
			return
		}
		var reply bool
		err := rpcdvl.AddVisualizationPolicyRpc(context.Background(), &dataVisualization2.ArgsCardPolicy{
			TransNo: res.TransNo,
			IsRenew: res.IsRenew,
		},&reply)
		if err != nil {
			utils.Logerr.Printf("统计保单出单成功任务失败 保单流水号 TranNo: %s error : %s\n", res.TransNo, err)
		}
		// 预付卡保险出单
		if err = rpcComtreeData.AddInsuranceBillRpc(context.Background(),&res.TransNo,&reply);err != nil {
			logs.Error("预付卡保险出单，失败信息：TranNo: %s error : %s \n", res.TransNo, err.Error())
		}

	})
	if err != nil {
		utils.Logerr.Printf("统计保单出单成功任务失败 err: %s", err.Error())
	}

}